package com.smartjobs.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.smartjobs.bean.CompanyBean;
import com.smartjobs.bean.JobpostingCompanySkillBean;
import com.smartjobs.bean.SkillMasterBean;
import com.smartjobs.util.DBManager;

public class ViewCompanyDataModel {

	public static void GetCompanyProfile(CompanyBean company) {

		String query = "select * from smartjobs.companyprofile where companyId = "
				+ company.getCompanyID();

		ResultSet result = DBManager.selectFromDB(query);

		try {
			if (result.next()) {
				company.setCompanyName(result.getString(2));
				company.setEmailID(result.getString(3));
				company.setPhoneNumber(result.getString(5));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void GetJobpostings(int companyID,
			ArrayList<JobpostingCompanySkillBean> jobpostingList) {

		String query = "SELECT * FROM smartjobs.jobpostingCompanySkill_view where companyId = "
				+ companyID;

		ResultSet result = DBManager.selectFromDB(query);

		try {
			while (result.next()) {
				JobpostingCompanySkillBean jobposting = new JobpostingCompanySkillBean();
				jobposting.setCompanyID(Integer.parseInt(result.getString(8)
						.toString()));
				jobposting.setCompanyName(result.getString(6));
				jobposting.setJobCode(result.getString(2));
				jobposting.setJobDesc(result.getString(3));
				jobposting.setJobID(Integer.parseInt(result.getString(1)
						.toString()));
				jobposting.setLocation(result.getString(4));
				jobposting.setQualification(result.getString(5));
				jobposting.setSkillName(result.getString(7));
				jobpostingList.add(jobposting);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void DeleteJobPosting(int jobID) {

		String query = "DELETE FROM `smartjobs`.`jobposting` WHERE `jobId`="
				+ jobID;

		DBManager.deleteFromDB(query);

	}
}
